import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";

function createMesh(color, x) {
	const geometry = new THREE.DodecahedronGeometry(100);
	const material = new THREE.MeshPhongMaterial({
		color: color,
	});
	const mesh = new THREE.Mesh(geometry, material);
	mesh.position.x = x;
	return mesh;
}
const group = new THREE.Group();

const mesh = createMesh("orange", 0);
const mesh2 = createMesh("skyblue", 300);
const mesh3 = createMesh("lightgreen", -300);

const loader = new GLTFLoader();
loader.load("/assets/model/Horse.gltf", (gltf) => {
	const horse = gltf.scene;
	horse.scale.set(20, 20, 20);
	horse.position.set(0, 200, 0);
	horse.rotation.y = Math.PI / 2; // 调整马的朝向
	horse.traverse((obj) => {
		if (obj.isMesh) {
			if (obj.name === "Cylinder") {
				obj.material.color = new THREE.Color("white");
			} else if (obj.name === "Cylinder_1") {
				obj.material.color = new THREE.Color("pink");
			}
		}
	});

	group.add(horse);
});

group.add(mesh);
group.add(mesh2);
group.add(mesh3);

export default group;
